﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

/// <summary>
/// Summary description for Formatter
/// </summary>
public class Formatter
{


    public static IHtmlObject AddClass(string method, IHtmlObject obj)
    {
        obj.AddAttribute(HtmlConstants.CLASS, ClassLookUp.lookup(obj.GetType().Name));
        obj.AddAttribute(HtmlConstants.CLASS, ClassLookUp.lookup(method));
        return obj;
    }

    public static HtmlContainer AddChild(IHtmlObject parent, IHtmlObject child)
    {
        HtmlContainer result = (HtmlContainer)parent;
        if(parent is HtmlContainer)
        {
            result.AddChild(child);
        }
        return result;
    }

	public static string SearchResult(string imageUrl, string result, string description)
	{
        IHtmlObject rc = new HtmlContainer(HtmlConstants.DIV);
        rc = AddClass(MethodBase.GetCurrentMethod().DeclaringType.Name, rc);
        IHtmlObject ric = new HtmlContainer(HtmlConstants.DIV);
        ric = AddClass(MethodBase.GetCurrentMethod().DeclaringType.Name, ric);
        rc = AddChild(rc, ric);
        IHtmlObject it = new HtmlTag(HtmlConstants.IMAGE);
        it.AddAttribute(HtmlConstants.SOURCE, imageUrl);
        ric = AddChild(ric, it);
        IHtmlObject resCon = new HtmlContainer(HtmlConstants.DIV);
        resCon = AddClass(MethodBase.GetCurrentMethod().DeclaringType.Name, resCon);
        IHtmlObject rt = HtmlContainer(HtmlContainer

		return
		"<div class='resultItem'>"
			+ "<div class='resultImage'>"
				+ "<img src='" + url + "'/>"
			+ "</div>"
			+ "<div class='resultContainer'>"
				+ "<div class='resultTitle'>" + result + "</div>"
				+ "<div class='resultDescription'>" + description + "</div>"
			+ "</div>"
		+ "</div>";
	}

	public static string Members(string url, string name, string description)
	{
		// <div> <Img/></div><div><div>Result</div><div>Discription</div></div>
		return
		"<div class='memberItem'>"
			+ "<div class='memberImage'>"
				+ "<img src='" + url + "'/>"
			+ "</div>"
			+ "<div class='memberContainer'>"
				+ "<div class='memberName'>" + name + "</div>"
				+ "<div class='memberDescription'>" + description + "</div>"
			+ "</div>"
		+ "</div>";
	}

	public static string About(string aboutText)
	{
		return "<div class='aboutText'>" + aboutText + "</div>";
	}

	public static string News(string date, string title, string message)
	{
		return "<div class='newsDate'>"+date+"</div><div class='newsTitle'>"+title+"</div><div class='newsMessage'>"+message+"</div>";
	}

	public static string Company(string imageUrl, string companyName, string description, string websiteUrl)
	{
		return "<div class='companyImage'><img src='"+imageUrl+"'></div><div class='companyName'>"+companyName+"</div><div class='companydescription'>"+description+"</div><div class='companyWebsite'>"+websiteUrl+"</div>";
	}

    public static string Badge(string imageUrl, string projectName, string description, string url)
    {
        string image = imageGenerator(imageUrl);
        string name = divGenerator("badgeProjectName", projectName);
        string desc = divGenerator("badgeDescription", description);
        string link = hrefGenerator(url, "Go to project page");
        string containerLower = divGenerator("badgeLowerContainer", image + desc);
        string containerMain = divGenerator("badge", name + containerLower + link);
        return containerMain;
    }

    public static string divGenerator(string className, string contents)
    {
        return "<div class='" + className + "'>" + contents + "</div>";
    }
    public static string imageGenerator(string className, string imageUrl, string altCaption)
    {
        return "<img src='" + imageUrl + "' class='" + className + "' alt='" + altCaption + "'/>";
    }
    public static string imageGenerator(string className, string imageUrl)
    {
        return imageGenerator(className, imageUrl, "");
    }
    public static string imageGenerator(string imageUrl)
    {
        return imageGenerator("", imageUrl, "");
    }
    public static string hrefGenerator(string url, string content)
    {
        Dictionary<string,string> attributes
        tagGenerator("a",
        return "<a href='" + url + "'>" + content + "</a>";
    }
    public static string tagGenerator(string tag, Dictionary<string, string> attributes, string content)
    {
        string tempAttr = "";
        foreach (string s in attributes.Keys)
        {
            tempAttr += s + "='" + attributes[s] + "' ";
        }
        return String.Format("<{0} {1}> {2} </{0}>", tag, tempAttr, content);
    }
}